<?php
if ($authorImage == "")
    $authorImage = "http://localhost/default.png";
Echo "<img src=" . $authorImage . ">";
?><br></br><span style="color:green"><?php echo $returnedTweet[0]['post']['text']; ?> <br> 
    <?php echo "Tweeted on " . $returnedTweet[0]['post']['time'] . "  by  " . $tweetAuthor; ?></span>
<br></br>
<p><span style="color:red"><?php echo h($task['Task']['originalMessage']) ?>   by <?php echo $task['Task']['sentBy']; ?>
        Created on : <?php echo $task['Task']['taskDate'] ?></span></p>
<?php
foreach ($messages as $message) {
    ?> <br></br><?php
        $color;
        if ($message['Message']['userID'] == $userName) {
            $color = "blue";
        } else {
            $color = "black";
        }
    ?><li><span style ="color:<?php echo $color; ?>"><?php
    echo $message['Message']['messageText'];
    echo " on " . $message['Message']['messageDate'] . " by " . ($message['Message']['userID']);
    ?></span></li><?php
    }
    echo $this->Form->create('Message');
    if ($taskStatus != 'complete') {
        if ($isAssignee || $isAuthor)
            echo $this->Form->input('messageText', array('rows' => '3', 'style' => 'width:500px', 'label' => 'Message'));
    }
    echo $this->Form->input('taskID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $taskID));
    echo $this->Form->input('userID', array('style' => 'width:500px', 'type' => 'hidden', 'value' => $userID));
    if ($isAssignee) {
        if ($taskStatus !== 'complete') {
            echo $this->Form->input('status', array('type' => 'checkbox', 'options' => 'done', 'label' => 'Task Completed'));
        }
    }

    if ($taskStatus != 'complete') {
        if ($isAssignee || $isAuthor)
            echo $this->Form->end('Submit Message');
    }
?>

<div id="third" style="border:0px solid black;position:absolute;top:100;right:0;float:right;float:top;height:100%;width:20%">
    <div id="container3">
        <div id="content3">
            <div id ="header">

                <p><span style="color:green">Tweet Text</p></span> 
                <p><span style="color:red">Task Message</p></span>
                <p><span style="color:blue">My Messages</p></span>
                <p><span style="color:black">Other Messages</p></span>
                <h4> sent by </h4>

                <?php
                foreach ($users as $user) {
                    if ($user['tasks_has_users']['permissionLevel'] == 'author') {
                        if ($user['tasks_has_users']['image'] == null)
                            $user['tasks_has_users']['image'] = "http://localhost/default.png";
                        echo "<img src=" . $user['tasks_has_users']['image'];
                        ?> <br></br> <?php echo $user['tasks_has_users']['username']; ?> <br></br><?php
            }
        }
                ?>

                <?php
                $flag = true;
                foreach ($users as $user) {
                    if ($user['tasks_has_users']['permissionLevel'] == 'reassigner') {
                        if ($flag) {
                            ?><br><h4>re assigned by</h4></br><?php
                $flag = false;
            }
            if ($user['tasks_has_users']['image'] == null)
                $user['tasks_has_users']['image'] = "http://localhost/default.png";
            echo "<img src=" . $user['tasks_has_users']['image'];
                        ?> <br></br> <?php
                echo $user['tasks_has_users']['username'];
                        ?>  <br></br><?php
            }
        }
                ?>
                <?php
                $flag = true;
                foreach ($users as $user) {

                    if ($user['tasks_has_users']['permissionLevel'] == 'assignee' && $user['tasks_has_users']['status'] == 'accepted') {
                        if ($flag) {
                            ?><br><h4>Users who accepted the task </h4></br><?php
                $flag = false;
            }
            if ($user['tasks_has_users']['image'] == null)
                $user['tasks_has_users']['image'] = "http://localhost/default.png";
            echo "<img src=" . $user['tasks_has_users']['image'];
                        ?> <br></br> <?php echo $user['tasks_has_users']['username']; ?> <br></br><?php
            }
        }
                ?>
                <?php
                $flag = true;
                foreach ($users as $user) {
                    if ($user['tasks_has_users']['permissionLevel'] == 'assignee' && $user['tasks_has_users']['status'] == 'rejected') {
                        if ($flag) {
                            ?><br><h4>Users who rejected the task </h4></br> <?php
                $flag = false;
            }
            if ($user['tasks_has_users']['image'] == null)
                $user['tasks_has_users']['image'] = "http://localhost/default.png";
            echo "<img src=" . $user['tasks_has_users']['image'];
                        ?> <br></br> <?php echo $user['tasks_has_users']['username']; ?> <br></br><?php
            }
        }
                ?>
                <?php
                $flag = true;

                foreach ($users as $user) {
                    if ($user['tasks_has_users']['permissionLevel'] == 'assignee' && $user['tasks_has_users']['status'] == 'pending') {

                        if ($flag) {
                            ?> <br><h4>Pending Users </h4></br><?php
                $flag = false;
            }


            if ($user['tasks_has_users']['image'] == null)
                $user['tasks_has_users']['image'] = "http://localhost/default.png";
            echo "<img src=" . $user['tasks_has_users']['image'];
                        ?> <br></br> <?php echo $user['tasks_has_users']['username']; ?> <br></br><?php
            }
        }
                ?>



            </div>
        </div>
        <br/>
    </div>
</div>
